<template>
  <div class="menus-body" @mouseout="isAcitive=false">
    <div class="menus">
      <div
        class="menu-item"
        :class="{'active':isAcitive&&cityIndex==index}"
        v-for="(cities,index) in cityData"
        :key="index"
        @mousemove="activeSubMenus(index)"
      >
        <span>{{cities.type}}</span>
      </div>
    </div>
    <div class="sub-menus" v-if="cityData&&isAcitive" @mousemove="isAcitive=true">
      <ul>
        <li  
         @click="searchMessage(index)"
        v-for="(item,index) in this.childrenList"
         :key="index">
          <a href="#" class="nuxt-link-active">
            <i>{{index+1}}</i>
            <strong>{{item.city}}</strong>
            <span>{{item.desc}}</span>
          </a>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      cityData: null,
      isAcitive: false,
      cityIndex: "",
      childrenList:[]
    };
  },
  mounted() {
    this.$axios({
      url: "/posts/cities"
    }).then(res => {
      this.cityData = res.data.data;
      console.log(this.cityData);
    });
  },
  watch: {
    isAcitive() {
      console.log(this.isAcitive);
    }
  },
  methods: {
     searchMessage(index) {
      this.$emit("getContent", this.childrenList[index].city);
      this.isAcitive=false
    },
    activeSubMenus(newIndex) {
      this.isAcitive = true;
      this.childrenList=this.cityData[newIndex].children
      this.cityIndex = newIndex;
    },

  }
};
</script>

<style lang="less" scoped>
.menus {
  width: 260px;
  border: 1px solid #ddd;
  border-right: none;
  border-bottom: none;
  box-shadow: 0 0 1px #f5f5f5;
  z-index: 2;
  .menu-item {
    height: 40px;
    line-height: 40px;
    border-bottom: 1px solid #ddd;
    border-right: 1px solid #ddd;
    padding: 0 20px;
    font-size: 14px;
    position: relative;
    z-index: 2;
    &:after {
      display: block;
      content: "";
      width: 10px;
      height: 10px;
      border-right: 1px solid #999;
      border-top: 1px solid #999;
      transform: rotate(45deg);
      position: absolute;
      right: 20px;
      top: 15px;
    }
    &.active {
      border-right-color: #fff;
      color: orange;
      &:after {
        display: block;
        content: "";
        width: 10px;
        height: 10px;
        border-right: 1px solid orange;
        border-top: 1px solid orange;
        transform: rotate(45deg);
        position: absolute;
        right: 20px;
        top: 15px;
      }
    }
  }
}
.sub-menus {
  position: absolute;
  left: 260px;
  top: 0;
  width: 350px;
  padding: 10px 20px;
  box-sizing: border-box;
  background-color: #fff;
  border: 1px solid #ddd;
  ul {
    li {
      font-size: 14px;
      line-height: 1.5;
      * {
        vertical-align: middle;
        i {
          color: orange;
          font-size: 24px;
          font-style: italic;
        }
        strong {
          margin: 0 10px;
          color: orange;
          font-weight: normal;
        }
        span {
          color: #999;
        }
      }
    }
  }
}
</style>